package de.akabahn.ebd.control;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

/**
 * @author Peter Eimann
 */
public class EBD_ChooseLoginActivity extends EBD_DefaultUncaughtExceptionHandler implements OnClickListener {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chooselogin);
	}

	@Override
	protected void onStart() {
		super.onStart();

		findViewById(R.id.chooselogin_button_registered).setOnClickListener(this);
		findViewById(R.id.chooselogin_button_unregistered).setOnClickListener(this);

		String errorMessage = getIntent().getStringExtra("de.akabahn.ebd.control.errormessage");
		TextView errorMessageView = (TextView)findViewById(R.id.chooselogin_errorMessage);
		if (errorMessage != null) {
			errorMessageView.setTextColor(Color.RED);
			errorMessageView.setText(getResources().getString(R.string.chooselogin_errorMessageText, errorMessage));
			getIntent().putExtra("de.akabahn.ebd.control.errormessage", (String)null);
		} else {
			errorMessageView.setText("");
		}

		String stackTrace = getIntent().getStringExtra("de.akabahn.ebd.control.stacktrace");
		TextView stackTraceView = (TextView)findViewById(R.id.chooselogin_stackTrace);
		if (stackTrace != null) {
			stackTraceView.setTextColor(Color.GRAY);
			stackTraceView.setText(getResources().getString(R.string.chooselogin_stackTraceText, stackTrace));
			getIntent().putExtra("de.akabahn.ebd.control.stacktrace", (String)null);
		} else {
			stackTraceView.setText("");
		}
	}

	@Override
	public void onClick(View v) {
		Intent next = null;

		switch (v.getId()) {
			case R.id.chooselogin_button_registered:
				next = new Intent(v.getContext(), EBD_RegisteredLoginActivity.class);
				break;
			case R.id.chooselogin_button_unregistered:
				next = new Intent(v.getContext(), EBD_UnregisteredLoginActivity.class);
				break;
		}

		startActivity(next);
	}
}
